<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("../conn.php");
require_once("../change_page.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>乐知家园</title>
        <script language="javascript">
            function deleteproduct(id,name,page){
                var str = "\u786e定删除 " + name + "\uff1f";
                if(confirm(str)){
                    location.href = "deleteQuestion.php?ids=" + id + "&page=" + page;
                }
            }

            function search_key(){
                var key = document.getElementById("keyword").value;
                if(key==null||key==''){
                    alert("\u8bf7输入关键字");
                } else {
                    var page = document.getElementById("current_page").value;
                    location.href = "questionList.php?keyword=" + key + "&page=" + page+"&menu=question";
                }
            }

            function click_all(e){
                var checkboxes = document.getElementsByName("product_checkbox");
                for(var i=0;i<checkboxes.length;i++){
                    if(e.checked){
                        checkboxes[i].checked = true;
                    }else{
                        checkboxes[i].checked = false;
                    }
                }
            }
            function delete_product_multi(page){
                var str = "\u786e定删除选中的应用？";
                if(confirm(str)){
                    var ids = "";
                    var checkboxes = document.getElementsByName("product_checkbox");
                    for(var i=0;i<checkboxes.length;i++){
                        if(checkboxes[i].checked){
                            ids = ids + checkboxes[i].value + ",";
                        }
                    }
                    location.href = "deleteQuestion.php?ids=" + ids + "&page=" + page;
                }
            }
            function approve(id,direct,name,page){
                var str = "";
                if(direct=="up"){
                    str = name + " \u786e定发布？";
                }else if(direct=="down"){
                    str = name + " \u786e定下线？";
                }
                if(confirm(str)){
                    location.href = "approveQuestion.php?ids=" + id + "&direct=" + direct + "&page=" + page;
                }
            }
            function approve_multi(direct,page){
                var str = "";
                if(direct=="up"){
                    str = "\u786e定发布选中的应用？";
                }else if(direct=="down"){
                    str = " \u786e定下线选中的应用？";
                }
                if(confirm(str)){
                    var ids = "";
                    var checkboxes = document.getElementsByName("product_checkbox");
                    for(var i=0;i<checkboxes.length;i++){
                        if(checkboxes[i].checked){
                            ids = ids + checkboxes[i].value + ",";
                        }
                    }
                    location.href = "approveQuestion.php?ids=" + ids + "&direct=" + direct + "&page=" + page;
                }
            }
        </script>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #000000;
            }

            .STYLE1 {color: #FFFFFF}
            -->
        </style></head>
    <body>
        <br/>
        <?php
        $page_size = 100;
        if (isset($_GET['page'])) {
            $page = $_GET['page'];
        } else {
            $page = 0;
        }
        ?>
        <table width="90%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
            <tr align="align">
                <td bgcolor="#FFFFFF"><a href="questionEdit.php?menu=question&page=<?php echo $page;?>">新建</a>&nbsp;<a href="#" onclick="delete_product_multi(<?php echo $page;?>)">删除</a>&nbsp;<a href="#" onclick="approve_multi('up','<?php echo $page; ?>')">发布</a></td>
                <td bgcolor="#FFFFFF" align="left">上传题目资源
                    <form id="form1" name="form1" method="post" action="csv.php" enctype="multipart/form-data">
                        <input name="csv_file" type="file" size="20" />
                        <input type="submit" name="Submit" value="提交" />
                    </form></td>
                <td><a href="questionAnswerList.php?menu=question">答案资源</a>&nbsp;&nbsp;<a href="questionVoiceList.php?menu=question">声音资源</a></td>
                <td>搜索编号、名称 <input type="text" name="keywork" id="keyword" value="" /> <input type="button" value="搜索" onclick="search_key()" /></td>
                <td bgcolor="#FFFFFF" align="right"><?php
                $age_sql_where = "";
                $age_sql_and = "";
                if (isset($_GET['keyword'])) {
                    $keyword = trim($_GET['keyword']);                    
                    $sql = "SELECT COUNT(*) AS total FROM t_game_question WHERE (code LIKE '%" . $keyword . "%' OR name LIKE '%" . $keyword . "%')" . $age_sql_and;
                } else {
                    $sql = "SELECT COUNT(*) AS total FROM t_game_question " . $age_sql_where;
                }

                $db = new DBC();
                $total_num = $db->fetchData($sql);
                if ($total_num != null) {
                    $total_num_product = $total_num[0]['total'];
                }
                $page_count = getPageSize($total_num_product, $page_size);
                echo getPage("questionList.php?menu=question", $page_count, $page);
                ?></td>
            </tr>
        </table>
        <br/>
        <table width="90%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#9999FF">
            <tr align="center">
                <td bgcolor="#666666" width="3%"><input name="all" type="checkbox" onclick="click_all(this)" /><input name="current_page" id="current_page" type="hidden" value="<?php echo $page; ?>" /></td>
                <td bgcolor="#666666" width="3%"><span class="STYLE1">序号</span></td>
                <td bgcolor="#666666" width="8%"><span class="STYLE1">编号</span></td>
                <td bgcolor="#666666" width="14%"><span class="STYLE1">名称</span></td>
                <td bgcolor="#666666" width="8%"><span class="STYLE1">题目语音1</span></td>
                <td bgcolor="#666666" width="8%"><span class="STYLE1">题目语音2</span></td>
                <td bgcolor="#666666" width="8%"><span class="STYLE1">题目图片</span></td>
                <td bgcolor="#666666" width="8%"><span class="STYLE1">正确答案</span></td>
                <td bgcolor="#666666" width="8%"><span class="STYLE1">错误答案1</span></td>
                <td bgcolor="#666666" width="8%"><span class="STYLE1">错误答案2</span></td>
                <td bgcolor="#666666" width="8%"><span class="STYLE1">错误答案3</span></td>
                <td bgcolor="#666666" width="8%"><span class="STYLE1">错误答案4</span></td>
                <td bgcolor="#666666" width="8%"><span class="STYLE1">错误答案5</span></td>                
                <td bgcolor="#666666" width="3%"><span class="STYLE1">版本</span></td>
                <td bgcolor="#666666" width="6%"><span class="STYLE1"><a href="questionList.php?order=status&menu=question">状态</a></span></td>
                <td bgcolor="#666666" width="10%"><span class="STYLE1">操作</span></td>
            </tr>
            <?php
            $begin = $page * $page_size;
            if (isset($_GET['keyword'])) {
                $keyword = $_GET['keyword'];
                $keyword = trim($keyword);
                $sql = "SELECT * FROM t_game_question WHERE (code LIKE '%" . $keyword . "%' OR name LIKE '%" . $keyword . "%') " . $age_sql_and . " ORDER BY code LIMIT " . $begin . "," . $page_size;
            } else {
                $sql = "SELECT * FROM t_game_question " . $age_sql_where . " ORDER BY code LIMIT " . $begin . "," . $page_size;
            }
            if (isset($_GET['order']) && $_GET['order'] == "status") {
                $sql = "SELECT * FROM t_game_question " . $age_sql_where . " ORDER BY status LIMIT " . $begin . "," . $page_size;
            }
            $num = $begin;
            $data = $db->fetchData($sql);
            foreach ($data as $product) {
                if ($product['status'] == "0") {
                    $status = "<font color='brown'>未发布</font>";
                } else if ($product['status'] == "1") {
                    $status = "<font color='green'>已发布</font>";
                }
                ?>
                <tr>
                    <td bgcolor="#FFFFFF" align="center"><input type="checkbox" name="product_checkbox" value="<?php echo $product['code']; ?>"/></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo++$num; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['code']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['name']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['voice1']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['voice2']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['pic']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['answer']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['answer1']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['answer2']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['answer3']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['answer4']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['answer5']; ?></td>                    
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['version']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<span title="<?php echo $product['url']; ?>"><?php echo $status; ?></span></td>
                    <td align="center" bgcolor="#FFFFFF"><a href="questionEdit.php?code=<?php echo $product['code']; ?>&page=<?php echo $page; ?>">编辑</a>
                        <a href="#" onclick="deleteproduct('<?php echo $product['code']; ?>','<?php echo $product['name']; ?>','<?php echo $page; ?>')">删除</a></td>
                </tr>
            <?php } ?>
        </table>
    </body>
</html>
<?php
include_once '../footer.php';
//} else {
//    header("login.php");
//}
?>